package lecode;

import java.util.HashSet;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-08-01
 * Time: 9:36
 */
public class Lecode {

    class Solution {
        //石头与宝石
        public int numJewelsInStones(String jewels, String stones) {
            HashSet<Character> hashset = new HashSet<>();
            char[] j = jewels.toCharArray();
            for(char val: j){
                if (!hashset.contains(val)){
                    hashset.add(val);
                }
            }
            char[] s = stones.toCharArray();
            int count = 0;
            for(char val:s){
                if (hashset.contains(val)){
                    count++;
                }
            }
            return count;
        }

    }


    /*
     *//*
     * 测试坏的键盘的值*//*
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str1= in.nextLine();
            String str2= in.nextLine();
            func(str1,str2);
        }

    }

    *//*力扣上的题
    * 输出坏的键盘的值*//*
    public static void func(String str1 , String str2){
    *//*关键是让坏掉的输入做set
    * 让好的输入去与set比较
    * 不能反过来
    * 最后一步避免重复就行*//*

        HashSet<Character> set2 = new HashSet();
        char[] ch2 = str2.toUpperCase().toCharArray();
        for(char ch : ch2){
            set2.add(ch);
        }


        HashSet<Character> set1 = new HashSet();
        char[] ch1 = str1.toUpperCase().toCharArray();
        for(char ch : ch1){
            if(!set1.contains(ch) && !set2.contains(ch)){//前者是避免重复元素的打印，后者为了打印坏掉的键盘
                System.out.print(ch);
                set1.add(ch);
            }
        }

    }
    */


/*
* 138. 随机链表的复制*/
/*
// Definition for a Node.
class Node {
    int val;
    Node next;
    Node random;

    public Node(int val) {
        this.val = val;
        this.next = null;
        this.random = null;
    }
}

    class Solution {
        public Node copyRandomList(Node head) {
            //第零步实例化一个Map类型<Node,Node>的Map
            Map<Node,Node> map = new HashMap<>();
            Node cur = head;
            //第一步:第一遍遍历，cur每走一步实例化一个节点存储val值
            //第二步把旧链表的每一个节点和新链表的每一个节点的地址都存入map中
            while(cur != null){
                Node node = new Node(cur.val);
                map.put(cur,node);
                cur = cur.next;
            }
            //第三步：第二遍遍历，确定新链表的next值和random的值
            //新链表的节点地址  map.get(cur).next = map.get(cur.next)
            //map.get(cur).radom = map.get(cur.random)
            cur = head;
            while(cur != null){
                map.get(cur).next = map.get(cur.next);
                map.get(cur).random = map.get(cur.random);
                cur = cur.next;
            }
            //返回复制链表的头结点
            return map.get(head);

        }
    }
    */


}
